/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package myprogramui.comp;

import Globals.AllGlobal;
import brain.MyBrain;
import com.jme3.math.FastMath;
import controller.MyController;
import database.operate.OperateMyDatabaseImpl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.event.EventHandler;
import javafx.geometry.Bounds;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.Tooltip;
import javafx.scene.control.TreeItem;
import javafx.scene.effect.Bloom;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.EllipseBuilder;
import javafx.scene.shape.Line;
import javafx.scene.shape.LineBuilder;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.RectangleBuilder;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.text.TextBuilder;
import javafx.stage.Stage;
import model.GongZuoMian_Model;
import model.ZuanChang_Model;
import model.ZuanKong_Model;
import myprogramui.comp.page2comp.RightTree;

/**
 *
 * @author Administrator
 */
public class DrillPage extends Group{
    //各种初始化
    private Button drawBut;
    private Text tjxx;
    private Line tjxxLine;
    private Line tjxxLine1;
    private Text zksl;private int zkslcount=0;
    private Text zjztj;private float zjztjF=0;
    
    private Text zcsl;
    private Text zyfhsl;private int zyfhs=0;
    private Text yssl;
    private Line ysslLine;
    private Line ysslLine1;
    private ImageView cir1;
    private ImageView cir2;
    private ImageView cir3;
    private ImageView cir4;
    private ImageView cir5;
    private ImageView cir6;
    private ImageView cir7;
    private ImageView cir8;
    private Text text1;
    private Text text2;
    private Text text3;
    private Text text4;
    private Text text5;
    private Text text6;
    private Text text7;
    private Text text8;
    private Text tyhz;//投影绘制
    private ImageView dropTreeBut;
    private ProgressBar pb;
    //设置各种tooltip
    Tooltip treeTip = new Tooltip("点击展开钻孔树");
    
    Tooltip t1Tip = new Tooltip("水压0-20MPa");
    Tooltip t2Tip = new Tooltip("水压21-40MPa");
    Tooltip t3Tip = new Tooltip("水压大于40MPa");
    Tooltip t4Tip = new Tooltip("钻孔在奥灰层小于最大距离，有效");
    Tooltip t5Tip = new Tooltip("钻孔在奥灰层大于最大距离，无效");
    Tooltip t6Tip = new Tooltip("终压符合极限设定值");
    Tooltip t7Tip = new Tooltip("终压不符合极限设定值");
    Tooltip t8Tip = new Tooltip("出水点示意");
    
    Tooltip pbTip = new Tooltip("显示绘制进度");
    //TreeView<String> tree = new TreeView<String> (); 
    private RightTree tree;
    private float fwjF=95.59f;
    private float sgqsgszbx=3919300;
    private float sgqsgszby=38464300;
    private float gzmgszbx=3919294;
    private float gzmgszby=38464380;
    private float qdx=0,qdy=0;//求三角形起点
    private float l=0;
    float diKaErX=0;
    float diKaErY=0;
    //下面是各个flag
    private boolean drawSG=false;
    private boolean drawHD=false;
    private boolean drawZK=false;
    private int zk_count=0,zk_total=0;
    private boolean drawKX=false;
    private int kx_count=0,kx_total=0;
    //因为要还原前一个的颜色，就必须记住前一个的颜色和名称，以便找到！
    private Color preColor;
    private Ellipse preCircle;
    private Color smallShuiColor=Color.rgb(157, 201, 55);
    private Color midShuiColor=Color.rgb(221, 68, 67);
    private Color bigShuiColor=Color.rgb(47, 146, 209);
    private Color zyFHColor=Color.rgb(225, 141, 35);    
    private Color zyBFColor=Color.rgb(229, 230, 52);
    private Color wxkColor=Color.rgb(70, 174, 53);
    private Color yxkColor=Color.rgb(184, 28, 34);
    //危险孔距离
    private float wxkjlF=25.0f;
    @Override
    public boolean intersects(Bounds localBounds) {
        return super.intersects(localBounds); //To change body of generated methods, choose Tools | Templates.
    }
    private MyController controller;
    private MyBrain brain;
    private Stage primaryStage;
    private Rectangle center;
    private Line line;
    private boolean flag1=false;
    private boolean flag2=true;
    private boolean flag3=true;
    Bloom bloom = new Bloom();
    private Rectangle mainRec;
    private Rectangle infoRec;
    private Rectangle colorRec;
    private Rectangle clipRec;
    private Group clipGroup=new Group();
    public DrillPage(Line line,Rectangle center,Stage primaryStage,MyController controller,MyBrain brain){
        clipRec=RectangleBuilder.create()
                .arcHeight(10)
                .arcWidth(10)
                .fill(Color.LIGHTSTEELBLUE)
                .stroke(Color.ANTIQUEWHITE)
                .strokeWidth(2)
                .width(860)
                .height(600)
                .build();
        clipRec.widthProperty().bind(primaryStage.widthProperty().multiply(0.67));
        clipRec.heightProperty().bind(primaryStage.heightProperty().multiply(0.71));
        clipRec.xProperty().bind(primaryStage.widthProperty().divide(8).add(35));
        clipRec.setTranslateY(140);
        
        this.controller=controller;
        this.brain=brain;
        tree=new RightTree(controller,brain);
        bloom.setThreshold(0.1);
        this.primaryStage=primaryStage;
        this.center=center;
        this.line=line;
        clipGroup.setAutoSizeChildren(true);
        //设置扩大缩小事件处理
        
        
        mainRec=RectangleBuilder.create()
                .arcHeight(10)
                .arcWidth(10)
                .fill(Color.LIGHTSTEELBLUE)
                .stroke(Color.ANTIQUEWHITE)
                .strokeWidth(2)
                .width(250)
                .height(200)
                .build();
        mainRec.widthProperty().bind(primaryStage.widthProperty().multiply(0.65));
        mainRec.heightProperty().bind(primaryStage.heightProperty().multiply(0.71));
        mainRec.xProperty().bind(primaryStage.widthProperty().divide(8).add(75));
        mainRec.setTranslateY(140);
        infoRec=RectangleBuilder.create()
                .arcHeight(10)
                .arcWidth(10)
                .fill(Color.LIGHTSTEELBLUE)
                .stroke(Color.BLUEVIOLET)
                .strokeWidth(2)
                .width(150)
                .height(150)
                .build();
        infoRec.xProperty().bind(primaryStage.widthProperty().subtract(200));
        infoRec.setTranslateY(140);
        colorRec=RectangleBuilder.create()
                .arcHeight(10)
                .arcWidth(10)
                .fill(Color.LIGHTSTEELBLUE)
                .stroke(Color.GRAY)
                .strokeWidth(2)
                .width(150)
                .height(360)
                .build();
        colorRec.xProperty().bind(primaryStage.widthProperty().subtract(200));
        colorRec.setTranslateY(310);
        this.getChildren().addAll(mainRec,infoRec,colorRec);
        /*
        **    下述是处理界面内容的，上述只是个框架。
        **/
        //统计信息
        tjxx=TextBuilder.create()
                .text("统计信息")
                .fill(Color.BLUEVIOLET)
                .font(new Font(14))
                .effect(bloom)
                .build();
        tjxx.xProperty().bind(primaryStage.widthProperty().subtract(185));
        tjxx.setTranslateY(160);
        tjxxLine=LineBuilder.create()
                .strokeWidth(4)
                .stroke(Color.rgb(255, 117, 0))
                .build();
        tjxxLine.startXProperty().bind(tjxx.xProperty().subtract(0));
        tjxxLine.startYProperty().bind(tjxx.translateYProperty().add(10));
        tjxxLine.endXProperty().bind(tjxx.xProperty().add(30));
        tjxxLine.endYProperty().bind(tjxx.translateYProperty().add(10));
        tjxxLine1=LineBuilder.create()
                .stroke(Color.LIGHTGRAY)
                .strokeWidth(1)
                .build();
        tjxxLine1.startXProperty().bind(tjxx.xProperty().add(3));
        tjxxLine1.startYProperty().bind(tjxx.translateYProperty().add(10));
        tjxxLine1.endXProperty().bind(tjxx.xProperty().add(90));
        tjxxLine1.endYProperty().bind(tjxx.translateYProperty().add(10));
        this.getChildren().add(tjxx);
        this.getChildren().add(tjxxLine);
        this.getChildren().add(tjxxLine1);
        //下面是文字
        zksl=TextBuilder.create()
                .font(new Font("楷体", 12))
                .text("钻孔总数量： 202个")
                .build();
        zksl.xProperty().bind(primaryStage.widthProperty().subtract(185));
        zksl.translateYProperty().bind(tjxx.translateYProperty().add(30));
        zjztj=TextBuilder.create()
                .font(new Font("楷体", 12))
                .text("注浆总体积： 202万吨")
                .build();
        zjztj.xProperty().bind(primaryStage.widthProperty().subtract(185));
        zjztj.translateYProperty().bind(tjxx.translateYProperty().add(55));
        zcsl=TextBuilder.create()
                .font(new Font("楷体", 12))
                .text("钻场数量： 55个")
                .build();
        zcsl.xProperty().bind(primaryStage.widthProperty().subtract(185));
        zcsl.translateYProperty().bind(tjxx.translateYProperty().add(80));
        zyfhsl=TextBuilder.create()
                .font(new Font("楷体", 12))
                .text("终压符数量： 175个")
                .build();
        zyfhsl.xProperty().bind(primaryStage.widthProperty().subtract(185));
        zyfhsl.translateYProperty().bind(tjxx.translateYProperty().add(105));
        this.getChildren().add(zksl);
        this.getChildren().add(zjztj);
        this.getChildren().add(zcsl);
        this.getChildren().add(zyfhsl);
        //颜色示例
        yssl=TextBuilder.create()
                .text("颜色示例")
                .fill(Color.BLUEVIOLET)
                .font(new Font(14))
                .effect(bloom)
                .build();
        yssl.xProperty().bind(primaryStage.widthProperty().subtract(155));
        yssl.setTranslateY(330);
        ysslLine=LineBuilder.create()
                .strokeWidth(4)
                .stroke(Color.rgb(255, 117, 0))
                .build();
        ysslLine.startXProperty().bind(yssl.xProperty().subtract(30));
        ysslLine.startYProperty().bind(yssl.translateYProperty().add(10));
        ysslLine.endXProperty().bind(yssl.xProperty());
        ysslLine.endYProperty().bind(yssl.translateYProperty().add(10));
        ysslLine1=LineBuilder.create()
                .stroke(Color.LIGHTGRAY)
                .strokeWidth(1)
                .build();
        ysslLine1.startXProperty().bind(yssl.xProperty().add(3));
        ysslLine1.startYProperty().bind(yssl.translateYProperty().add(10));
        ysslLine1.endXProperty().bind(yssl.xProperty().add(90));
        ysslLine1.endYProperty().bind(yssl.translateYProperty().add(10));
        this.getChildren().add(yssl);
        this.getChildren().add(ysslLine);
        this.getChildren().add(ysslLine1);
        /////////////画圈啊，还有对应的文字///////////////
        cir1=new ImageView("Image_no_pair/eicir/1.png");
        cir1.translateXProperty().bind(yssl.xProperty().subtract(28));
        cir1.translateYProperty().bind(yssl.translateYProperty().add(30));       
        cir2=new ImageView("Image_no_pair/eicir/2.png");
        cir2.translateXProperty().bind(yssl.xProperty().subtract(28));
        cir2.translateYProperty().bind(yssl.translateYProperty().add(70));
        cir3=new ImageView("Image_no_pair/eicir/3.png");
        cir3.translateXProperty().bind(yssl.xProperty().subtract(28));
        cir3.translateYProperty().bind(yssl.translateYProperty().add(110));
        cir4=new ImageView("Image_no_pair/eicir/4.png");
        cir4.translateXProperty().bind(yssl.xProperty().subtract(28));
        cir4.translateYProperty().bind(yssl.translateYProperty().add(150));
        cir5=new ImageView("Image_no_pair/eicir/5.png");
        cir5.translateXProperty().bind(yssl.xProperty().subtract(28));
        cir5.translateYProperty().bind(yssl.translateYProperty().add(190));
        cir6=new ImageView("Image_no_pair/eicir/6.png");
        cir6.translateXProperty().bind(yssl.xProperty().subtract(28));
        cir6.translateYProperty().bind(yssl.translateYProperty().add(230));
        cir7=new ImageView("Image_no_pair/eicir/7.png");
        cir7.translateXProperty().bind(yssl.xProperty().subtract(28));
        cir7.translateYProperty().bind(yssl.translateYProperty().add(270));
        cir8=new ImageView("Image_no_pair/eicir/8.png");
        cir8.translateXProperty().bind(yssl.xProperty().subtract(28));
        cir8.translateYProperty().bind(yssl.translateYProperty().add(310));
        
        text1=TextBuilder.create().text("水压0-20").font(new Font(18)).fill(smallShuiColor).build();
        text1.translateXProperty().bind(yssl.xProperty());
        text1.translateYProperty().bind(yssl.translateYProperty().add(45)); 
        text2=TextBuilder.create().text("水压21-40").font(new Font(18)).fill(midShuiColor).build();
        text2.translateXProperty().bind(yssl.xProperty());
        text2.translateYProperty().bind(yssl.translateYProperty().add(85)); 
        text3=TextBuilder.create().text("水压40-_").font(new Font(18)).fill(bigShuiColor).build();
        text3.translateXProperty().bind(yssl.xProperty());
        text3.translateYProperty().bind(yssl.translateYProperty().add(125)); 
        text4=TextBuilder.create().text("有效孔").font(new Font(18)).fill(yxkColor).build();
        text4.translateXProperty().bind(yssl.xProperty());
        text4.translateYProperty().bind(yssl.translateYProperty().add(165)); 
        text5=TextBuilder.create().text("危险孔").font(new Font(18)).fill(wxkColor).build();
        text5.translateXProperty().bind(yssl.xProperty());
        text5.translateYProperty().bind(yssl.translateYProperty().add(205)); 
        text6=TextBuilder.create().text("终压符合").font(new Font(18)).fill(zyFHColor).build();
        text6.translateXProperty().bind(yssl.xProperty());
        text6.translateYProperty().bind(yssl.translateYProperty().add(245)); 
        text7=TextBuilder.create().text("终压不符").font(new Font(18)).fill(zyBFColor).build();
        text7.translateXProperty().bind(yssl.xProperty());
        text7.translateYProperty().bind(yssl.translateYProperty().add(285)); 
        text8=TextBuilder.create().text("出水点").font(new Font(18)).fill(Color.rgb(195, 112, 170)).build();
        text8.translateXProperty().bind(yssl.xProperty());
        text8.translateYProperty().bind(yssl.translateYProperty().add(325)); 
        this.getChildren().add(cir1);
        this.getChildren().add(cir2);
        this.getChildren().add(cir3);
        this.getChildren().add(cir4);
        this.getChildren().add(cir5);
        this.getChildren().add(cir6);
        this.getChildren().add(cir7);
        this.getChildren().add(cir8);
        this.getChildren().add(text1);
        this.getChildren().add(text2);
        this.getChildren().add(text3);
        this.getChildren().add(text4);
        this.getChildren().add(text5);
        this.getChildren().add(text6);
        this.getChildren().add(text7);
        this.getChildren().add(text8);
        
        //投影绘制
        tyhz=TextBuilder.create()
                .text("投影绘制")
                .fill(Color.BLUEVIOLET)
                .font(new Font(14))
                .effect(bloom)
                .build();
        tyhz.xProperty().bind(primaryStage.widthProperty().divide(8).add(135));
        tyhz.setTranslateY(160);
        Line tyhzLine=LineBuilder.create()
                .strokeWidth(4)
                .stroke(Color.rgb(255, 117, 0))
                .build();
        tyhzLine.startXProperty().bind(tyhz.xProperty().subtract(30));
        tyhzLine.startYProperty().bind(tyhz.translateYProperty().add(10));
        tyhzLine.endXProperty().bind(tyhz.xProperty());
        tyhzLine.endYProperty().bind(tyhz.translateYProperty().add(10));
        Line tyhzLine1=LineBuilder.create()
                .stroke(Color.LIGHTGRAY)
                .strokeWidth(1)
                .build();
        tyhzLine1.startXProperty().bind(tyhz.xProperty().add(3));
        tyhzLine1.startYProperty().bind(tyhz.translateYProperty().add(10));
        tyhzLine1.endXProperty().bind(tyhz.xProperty().add(90));
        tyhzLine1.endYProperty().bind(tyhz.translateYProperty().add(10));
        this.getChildren().add(tyhz);
        this.getChildren().add(tyhzLine);
        this.getChildren().add(tyhzLine1);
        
        //这里添加下拉菜单。就是以前的树形菜单能够又隐又现，在按钮的作用下。
        dropTreeBut=new ImageView("Image_no_pair/page2/down.png");
        dropTreeBut.translateXProperty().bind(primaryStage.widthProperty().subtract(145));
        dropTreeBut.setTranslateY(120);
        //添加treeview，
        tree.setPrefSize(210, 570);
        tree.translateXProperty().bind(dropTreeBut.translateXProperty().subtract(90));
        tree.setTranslateY(120);
        tree.setVisible(false);
        this.getChildren().add(tree);
        dropTreeBut.setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                if(!tree.isVisible()){
                    dropTreeBut.setTranslateY(690);
                    tree.setVisible(true);
                    dropTreeBut.setImage(new Image("Image_no_pair/page2/up.png"));
                }else{
                    dropTreeBut.setTranslateY(120);
                    tree.setVisible(false);
                    dropTreeBut.setImage(new Image("Image_no_pair/page2/down.png"));
                }
                
            }
        });
        this.getChildren().add(dropTreeBut);
        //进度条
        pb=new ProgressBar();
        pb.setProgress(0);
        pb.setPrefWidth(540);
        pb.setTranslateX(470);
        pb.translateYProperty().bind(mainRec.translateYProperty().subtract(27));
        this.getChildren().add(pb);
        //添加绘制按钮和绘制进度条
        drawBut = new Button("绘制二维坐标投影图");
        
        drawBut.setTranslateX(300);
        drawBut.translateYProperty().bind(mainRec.translateYProperty().subtract(30));
        this.getChildren().add(drawBut);
        //单独有一个按键是找到危险孔的
        this.setOnKeyPressed(new EventHandler<KeyEvent>() {

            @Override
            public void handle(KeyEvent event) {
                if(event.getCode().equals(KeyCode.Q)){
                    Iterator<Node> it=clipGroup.getChildren().iterator();
                    while (it.hasNext()) {
                        boolean flagYX=false;
                        Node aNode=it.next();
                        Ellipse e=null;
                        if(aNode.getId()!=null&&aNode.getUserData()!=null){
                            e=(Ellipse)aNode;
                            Iterator<Node> it_inner=clipGroup.getChildren().iterator();
                            float distance=0;
                            innerloop:while (it_inner.hasNext()) {
                               Node innerNode=it_inner.next();
                               if(innerNode.getId()!=null&&innerNode.getUserData()!=null){
                                    Ellipse ei=(Ellipse)innerNode;
                                    double x=e.getTranslateX()-ei.getTranslateX();
                                    double y=e.getTranslateY()-ei.getTranslateY();
                                    distance=FastMath.sqrt((float) (x*x+y*y));
                                    if(distance!=0&&distance<=(wxkjlF*0.75f)){
                                        e.setStroke(yxkColor);
                                        flagYX=true;
                                        break innerloop;
                                    }
                                }  
                            }
                            if(!flagYX){
                                e.setStroke(wxkColor);
                            }
                        }    
                    }    
                }
                    
            }
        });
        //绘制事件
        drawBut.setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                if(drawSG==false){
                    try {
                        drawGrid(11, 5);
                        ArrayList<ZuanChang_Model> zkms=OperateMyDatabaseImpl.getAllResult(AllGlobal.ZUANCHANG_SQL);
                        zk_total=zkms.size();
                    } catch (Exception ex) {
                        Logger.getLogger(DrillPage.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }     
                if(drawHD==false)
                    drawGZM();
                if(drawZK==false){
                    pb.setProgress(zk_count*1.0f/zk_total);
                    drawCircle(zk_count);
                    drawKongXin(zk_count++);                    
                }
                if(drawZK){
                    if(tree.getRoot().getChildren().size()<1)
                        fillTree();
                    pb.setProgress(1);
                }
            }
        });
        
        
        //提供绘制二维图形的起始点。然后依照起点进行绘制。
        //设置Tree事件
        tree.setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                if(tree.getSelectionModel()!=null&&
                        tree.getSelectionModel().getSelectedItem()!=null&&
                        tree.getSelectionModel().getSelectedItem().getValue()!=null){
                    Iterator<Node> it0=clipGroup.getChildren().iterator();
                    Iterator<Node> it=clipGroup.getChildren().iterator();
                    while (it0.hasNext()) {
                        Node aNode=it0.next();
                        if(aNode.getId()!=null&&aNode.getUserData()!=null){
                            String flagPrefix=((String)aNode.getUserData()).substring(0,1);
                            if(flagPrefix.equals("0")){
                                Ellipse cirAim=(Ellipse)aNode;
                                cirAim.setStroke(zyBFColor);
                            }else{
                                Ellipse cirAim=(Ellipse)aNode;
                                cirAim.setStroke(zyFHColor);
                            }
                            
                        }
                    }
                    while (it.hasNext()) {
                        Node aNode=it.next();
                        if(aNode.getId()!=null&&aNode.getId().equals(tree.getSelectionModel().getSelectedItem().getValue())){
                            if(preCircle!=null){
                                preCircle.setStroke(preColor);
                            }
                            Ellipse cirAim=(Ellipse)aNode;
                            preCircle=cirAim;
                            preColor=(Color) cirAim.getStroke();
                            cirAim.setStroke(Color.RED);
                            break;
                        }else if(aNode.getUserData()!=null&&((String)aNode.getUserData()).substring(1).equals(tree.getSelectionModel().getSelectedItem().getValue())){
                            Ellipse cirAim=(Ellipse)aNode;
                            cirAim.setStroke(Color.BLUE);
                        }
                        
                    }

                }
            }
        });
        //组装信息提示
        Tooltip.install(dropTreeBut, treeTip);
        Tooltip.install(text1, t1Tip);
        Tooltip.install(text2, t2Tip);
        Tooltip.install(text3, t3Tip);
        Tooltip.install(text4, t4Tip);
        Tooltip.install(text5, t5Tip);
        Tooltip.install(text6, t6Tip);
        Tooltip.install(text7, t7Tip);
        Tooltip.install(text8, t8Tip);
        Tooltip.install(pb, pbTip);
        //添加clipGroup
        this.getChildren().add(clipGroup);
        clipGroup.setClip(clipRec);
    }
    public RightTree getTree(){
        return this.tree;
    }
    //下面就是我们要使用的功能
    //画网格线
    public void drawGrid(int gszbyCount,int gszbxCount){
        fwjF=controller.getFANGWEIJIAO();
        try {
            ArrayList<GongZuoMian_Model> gzmms= OperateMyDatabaseImpl.getAllResult(AllGlobal.GONGZUOMIAN_SQL);
            if(gzmms.size()>0){
                GongZuoMian_Model gzmm=gzmms.get(0);
                this.sgqsgszbx=Float.valueOf(gzmm.getSgqsgszbx());
                this.sgqsgszby=Float.valueOf(gzmm.getSgqsgszby());
            }
           
        } catch (Exception ex) {
            Logger.getLogger(MyController.class.getName()).log(Level.SEVERE, null, ex);
        }
        for(int i=0;i<gszbyCount;i++){
            Line lineCanzhao=new Line(-250, 0, 250, 0);
            lineCanzhao.setStroke(Color.WHITE);
            clipGroup.getChildren().add(lineCanzhao);
            lineCanzhao.setId("line_2d_x"+i);
            lineCanzhao.setRotate(-fwjF);
            lineCanzhao.setTranslateX(290+75*i);
            lineCanzhao.setTranslateY(400);
            
            /** Write text on the screen (HUD) */ 
            Text zbtext=TextBuilder.create()
                    .text(String.valueOf(sgqsgszby+i*100))///   sgqsgszby
                    .id("text_x"+i)
                    .stroke(Color.RED)
                    .fill(Color.RED)
                    .build();
            zbtext.setTranslateX(lineCanzhao.getTranslateX());
            zbtext.setTranslateY(650);
            
            clipGroup.getChildren().add(zbtext);
        }
        for(int j=0;j<gszbxCount;j++){
            Line lineCanzhao=new Line(-400, 0, 400, 0);
            lineCanzhao.setStroke(Color.WHITE);
            clipGroup.getChildren().add(lineCanzhao);
            lineCanzhao.setId("line_2d_y"+j);
            lineCanzhao.setRotate(-(fwjF+90));
            lineCanzhao.setTranslateX(400+290);
            lineCanzhao.setTranslateY(200+75*j);
            /** Write text on the screen (HUD) */ 
            Text zbtext=TextBuilder.create()
                    .text(sgqsgszbx+j*100-(gszbxCount-1)*100+"")///   sgqsgszby
                    .id("text_y"+j)
                    .stroke(Color.RED)
                    .fill(Color.RED)
                    .build();
            zbtext.setTranslateX(230);
            zbtext.setTranslateY(lineCanzhao.getTranslateY()+40);
            clipGroup.getChildren().add(zbtext); 
        }
        //寻找起始点 
        float x1=690,y1=500;
        float x2=290,y2=400;
        float x3=0,y3=0;
        float sita=fwjF-90;
        float beita=0,tanbeita=0;
        float alfa=0;
        float zjbc=0;//中介边长
        tanbeita=(x2-x1)/(y1-y2);
        beita=FastMath.atan(tanbeita);
        alfa=beita-sita*FastMath.DEG_TO_RAD;
        zjbc=FastMath.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
        y3=y2-zjbc*FastMath.sin(sita);
        x3=x2-zjbc*FastMath.cos(sita);
        qdx=x3;
        qdy=y3;
        //设置标记
        drawSG=true;
    }
    //由于我们的巷道无法确定，那么就尝试吧
    public void drawGZM(){
        
        
        try {
            float gzmcd=176.76f;   
            ArrayList<GongZuoMian_Model> gzmms= OperateMyDatabaseImpl.getAllResult(AllGlobal.GONGZUOMIAN_SQL);
            if(gzmms.size()>0){
                GongZuoMian_Model gzmm=gzmms.get(0);
                gzmcd=Float.parseFloat(gzmm.getGzmcd());
                gzmgszbx=Float.parseFloat(gzmm.getGzmgszbX());
                gzmgszby=Float.parseFloat(gzmm.getGzmgszbY());
            }
            
            l = FastMath.sqrt((gzmgszbx-sgqsgszbx+400)*(gzmgszbx-sgqsgszbx+400)+
                    (gzmgszby-sgqsgszby)*(gzmgszby-sgqsgszby));
            float sinCiTa=(gzmgszby-sgqsgszby)/l;
            float ciTa=FastMath.asin(sinCiTa);
            float beiTa=ciTa+(90-fwjF)*FastMath.DEG_TO_RAD;
            diKaErX=qdx+l*FastMath.sin(beiTa)+330;
            diKaErY=qdy-l*FastMath.cos(beiTa);
            
            Line gzmLine1=new Line(0, 0, 600, 0);
            Line gzmLine2=new Line(0, gzmcd*0.75, 600, gzmcd*0.75);
            Line gzmLine3=new Line(0, 0, 0, gzmcd*0.75);
            gzmLine1.setStroke(Color.BLACK);
            gzmLine2.setStroke(Color.BLACK);
            gzmLine3.setStroke(Color.BLACK);
            //移动
            gzmLine1.setTranslateX(diKaErX);
            gzmLine1.setTranslateY(diKaErY);
            gzmLine2.setTranslateX(diKaErX);
            gzmLine2.setTranslateY(diKaErY);
            gzmLine3.setTranslateX(diKaErX);
            gzmLine3.setTranslateY(diKaErY);
            //add
            clipGroup.getChildren().add(gzmLine1);
            clipGroup.getChildren().add(gzmLine2);
            clipGroup.getChildren().add(gzmLine3);
            
        } catch (Exception ex) {
            Logger.getLogger(DrillPage.class.getName()).log(Level.SEVERE, null, ex);
        }    
        drawHD=true;
    }
    //明天剩下的就是画圈就行了。
    public void drawCircle(int zc_pos){
        try {
            
            ArrayList<ZuanChang_Model> alist_tmp=OperateMyDatabaseImpl.getAllResult(AllGlobal.ZUANCHANG_SQL);
            zcsl.setText("钻场总数量："+alist_tmp.size());
            ZuanChang_Model zcm_tmp=alist_tmp.get(zc_pos);
            ArrayList<ZuanKong_Model> zkms=OperateMyDatabaseImpl.getAllResult(AllGlobal.ZUANKONG_SQL
                    ,"select * from zuankong where zuanchang='"+zcm_tmp.getMingcheng()+"';");
            Iterator<ZuanKong_Model> zIt=zkms.iterator();
            zkslcount+=zkms.size();
            zksl.setText("钻孔总数量："+zkslcount);
            while(zIt.hasNext()){
                
                ZuanKong_Model zkm=zIt.next();
                float vF=Float.parseFloat(zkm.getVa())+Float.parseFloat(zkm.getVb())+Float.parseFloat(zkm.getVc());
                zjztjF+=vF;
                
                float rF=brain.CaculateR_2D(Float.parseFloat(zkm.getKongshen())-20, Float.parseFloat(alist_tmp.get(0).getKongxilvString()), 1,
                        Float.parseFloat(zkm.getVa())+Float.parseFloat(zkm.getVb())+Float.parseFloat(zkm.getVc())
                        , AllGlobal.CYLINDER_TYPE);
                if(rF==0){
                    rF=0f;
                }else if(rF>100){
                    //如果孔深为零，则不需要这个孔了
                    if(Float.parseFloat(zkm.getKongshen())==0){
                        rF=0;
                    }
                }
                float longRF=0;
                if(Float.parseFloat(zkm.getQingjiao())!=0){
                    longRF=(float) (rF/Math.abs(FastMath.cos(FastMath.DEG_TO_RAD*Float.parseFloat(zkm.getQingjiao()))));
                }else{
                    longRF=rF;
                }
                
                Ellipse ellipse=EllipseBuilder.create().id(zkm.getMingcheng()).centerX(0).centerY(0).radiusX(rF*0.75f).radiusY(longRF*0.75f)
                        .fill(Color.rgb(0, 0, 0, 0)).stroke(Color.RED).build();
                Tooltip t=new Tooltip();
                t.setText("名称："+zkm.getMingcheng()+"\n钻场："+
                        zkm.getZuanchang()+"\n终压："+
                        zkm.getZhongya()+"\n注浆前："+
                        zkm.getZhujiangqian()+"MPa");
                Tooltip.install(ellipse, t);
                //Circle circle=CircleBuilder.create().id(zkm.getMingcheng()).centerX(0).centerY(0).radius(rF*0.75f).fill(Color.rgb(0, 0, 0, 0)).stroke(Color.RED).build();
                if(Float.parseFloat(zkm.getZhongya())>=controller.getZhongyajixian()){
                    zyfhs++;
                    ellipse.setStroke(zyFHColor);
                    ellipse.setUserData(1+zkm.getZuanchang());
                }else{
                    ellipse.setStroke(zyBFColor);
                    ellipse.setUserData(0+zkm.getZuanchang());
                }
                //偏转型移动
                float shuipingL=controller.getAhcjl()/FastMath.tan(Float.parseFloat(zkm.getQingjiao())*FastMath.DEG_TO_RAD);
                float ciTa=controller.getFANGWEIJIAO()-Float.parseFloat(zkm.getFangwei());
                float pzY=-shuipingL*FastMath.sin(ciTa*FastMath.DEG_TO_RAD)*0.75f;
                float pzX=shuipingL*FastMath.cos(ciTa*FastMath.DEG_TO_RAD)*0.75f;
                //钻场型移动
                ArrayList<ZuanChang_Model> alist=OperateMyDatabaseImpl.getOne(AllGlobal.ZUANCHANG_SQL, 
                        "select * from zuanchang where mingcheng='"+zkm.getZuanchang()+"';");
                if(!alist.isEmpty()){
                    //ZuanChang_Model zuanChang_Model=alist.get(0);
                    ellipse.setRotate(ciTa);
                    //笛卡尔移动
                    if(controller.getGZM_TYPE()==AllGlobal.GZM_TYPE_LEFT){
                        ellipse.setTranslateX(diKaErX+Float.parseFloat(zcm_tmp.getXdzby())*0.75f+pzX);
                        ellipse.setTranslateY(diKaErY+Float.parseFloat(zcm_tmp.getXdzbx())*0.75f+pzY);
                        
                    }else if(controller.getGZM_TYPE()==AllGlobal.GZM_TYPE_RIGHT){
                        ellipse.setTranslateX(diKaErX+controller.getGzmzxcd()*0.75f-Float.parseFloat(zcm_tmp.getXdzby())*0.75f+pzX);
                        ellipse.setTranslateY(diKaErY+Float.parseFloat(zcm_tmp.getXdzbx())*0.75f+pzY);
                        
                    }
                }                
                clipGroup.getChildren().add(ellipse);
                zjztj.setText("注浆总体积："+zjztjF+"");
                zyfhsl.setText("终压符合数量："+zyfhs+"");
            }
        } catch (Exception ex) {
            Logger.getLogger(DrillPage.class.getName()).log(Level.SEVERE, null, ex);
        }
        if(zk_count==zk_total-1){
            drawZK=true;
        }else{
            drawZK=false;
        }
    }
    //下面是画孔芯
    public void drawKongXin(int zc_pos){
        //这些要全部加入到button事件当中
        try {
            ArrayList<ZuanChang_Model> alist_tmp=OperateMyDatabaseImpl.getAllResult(AllGlobal.ZUANCHANG_SQL);
            ZuanChang_Model zcm_tmp=alist_tmp.get(zc_pos);
            ArrayList<ZuanKong_Model> zkms=OperateMyDatabaseImpl.getAllResult(AllGlobal.ZUANKONG_SQL
                    ,"select * from zuankong where zuanchang='"+zcm_tmp.getMingcheng()+"';");
            Iterator<ZuanKong_Model> zIt=zkms.iterator();
            int count=0;
            while(zIt.hasNext()){
                ZuanKong_Model zkm=zIt.next(); 
                float rF=1;
                Ellipse circle=EllipseBuilder.create().centerX(0).centerY(0).radiusX(rF*0.75f).radiusY(rF*0.75f).stroke(Color.GREEN).build();
                if(Float.parseFloat(zkm.getZhujiangqian())<=20){
                    circle.setStroke(smallShuiColor);
                    circle.setFill(smallShuiColor);
                }else if(Float.parseFloat(zkm.getZhujiangqian())<=40){
                    circle.setStroke(midShuiColor);
                    circle.setFill(midShuiColor);
                }else{
                    circle.setStroke(bigShuiColor);
                    circle.setFill(bigShuiColor);
                }
                //偏转型移动
                float shuipingL=controller.getAhcjl()/FastMath.tan(Float.parseFloat(zkm.getQingjiao())*FastMath.DEG_TO_RAD);
                float ciTa=controller.getFANGWEIJIAO()-Float.parseFloat(zkm.getFangwei());
                float pzY=-shuipingL*FastMath.sin(ciTa*FastMath.DEG_TO_RAD)*0.75f;
                float pzX=shuipingL*FastMath.cos(ciTa*FastMath.DEG_TO_RAD)*0.75f;
                //钻场型移动
                ArrayList<ZuanChang_Model> alist=OperateMyDatabaseImpl.getOne(AllGlobal.ZUANCHANG_SQL, 
                        "select * from zuanchang where mingcheng='"+zkm.getZuanchang()+"';");
                if(!alist.isEmpty()){
                    //ZuanChang_Model zuanChang_Model=alist.get(0);
                    //笛卡尔移动
                    if(controller.getGZM_TYPE()==AllGlobal.GZM_TYPE_LEFT){
                        circle.setTranslateX(diKaErX+Float.parseFloat(zcm_tmp.getXdzby())*0.75f+pzX);
                        circle.setTranslateY(diKaErY+Float.parseFloat(zcm_tmp.getXdzbx())*0.75f+pzY);
                        
                    }else if(controller.getGZM_TYPE()==AllGlobal.GZM_TYPE_RIGHT){
                        circle.setTranslateX(diKaErX+controller.getGzmzxcd()*0.75f-Float.parseFloat(zcm_tmp.getXdzby())*0.75f+pzX);
                        circle.setTranslateY(diKaErY+Float.parseFloat(zcm_tmp.getXdzbx())*0.75f+pzY);
                        
                    }
                }                
                clipGroup.getChildren().add(circle);

            }
        } catch (Exception ex) {
            Logger.getLogger(DrillPage.class.getName()).log(Level.SEVERE, null, ex);
        }
        if(zk_count==zk_total-1){
            drawZK=true;
        }else{
            drawZK=false;
        }
    }
    public void fillTree(){    
        try {
            ArrayList<GongZuoMian_Model> gzmlist=OperateMyDatabaseImpl.getAllResult(AllGlobal.GONGZUOMIAN_SQL);
            ArrayList<ZuanChang_Model> zclist=OperateMyDatabaseImpl.getAllResult(AllGlobal.ZUANCHANG_SQL);
            TreeItem<String> root=tree.getRoot();
            TreeItem<String> gzmItem=null;
            if(gzmlist.size()>0){
                gzmItem=new TreeItem<String>(gzmlist.get(0).getMingcheng());
                root.getChildren().add(gzmItem);
            }
            for(int i=0;i<zclist.size();i++){
                ZuanChang_Model zcm=zclist.get(i);
                TreeItem<String> zcItem=new TreeItem<String>(zcm.getMingcheng());
                gzmItem.getChildren().add(zcItem);
                ArrayList<ZuanKong_Model> zklist_tmp=OperateMyDatabaseImpl
                        .getAllResult(AllGlobal.ZUANKONG_SQL,"select * from zuankong where zuanchang='"+zcm.getMingcheng()+"';");
                for(int j=0;j<zklist_tmp.size();j++){
                    ZuanKong_Model zkm=zklist_tmp.get(j);
                    TreeItem<String> zkItem=new TreeItem<String>(zkm.getMingcheng());
                    zcItem.getChildren().add(zkItem);
                }
            }
        } catch (Exception ex) {
            Logger.getLogger(DrillPage.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public ArrayList<Integer> getYXWXK_Chart(){//为分析Page获取资料
        ArrayList<Integer> cList=new ArrayList();
        int gzmBW=0;
        int gzmWX=0;
        int jsBW=0;
        int jsWX=0;
        int gsBW=0;
        int gsWX=0;
        Iterator<Node> it=clipGroup.getChildren().iterator();
        while (it.hasNext()) {
            
            boolean flagYX=false;
            Node aNode=it.next();
            Ellipse e=null;
            if(aNode.getId()!=null&&aNode.getUserData()!=null){
                e=(Ellipse)aNode;
                Iterator<Node> it_inner=clipGroup.getChildren().iterator();
                float distance=0;
                String userName=((String)e.getUserData()).substring(1, 2);
                innerloop:while (it_inner.hasNext()) {
                   Node innerNode=it_inner.next();
                   if(innerNode.getId()!=null&&innerNode.getUserData()!=null){
                        Ellipse ei=(Ellipse)innerNode;
                        double x=e.getTranslateX()-ei.getTranslateX();
                        double y=e.getTranslateY()-ei.getTranslateY();
                        distance=FastMath.sqrt((float) (x*x+y*y));
                        if(distance!=0&&distance<=(wxkjlF*0.75f)){
                            //这是要处理三条分类的
                            if(userName.equals("胶")){
                                jsBW++;
                            }else if(userName.equals("轨")){
                                gsBW++;
                            }else{
                                gzmBW++;
                            }
                            flagYX=true;
                            break innerloop;
                        }
                    }  
                }
                if(!flagYX){
                    if(userName.equals("胶")){
                                jsWX++;
                    }else if(userName.equals("轨")){
                        gsWX++;
                    }else{
                        gzmWX++;
                    }
                }
            }
        }   
        cList.add(0,jsBW);
        cList.add(1,jsWX);
        cList.add(2,gsBW);
        cList.add(3,gsWX);
        cList.add(4,gzmBW);
        cList.add(5,gzmWX);
        return cList;
    }
    public ArrayList<Integer> getYXWXK_Table(){
        ArrayList<Integer> tList=new ArrayList();
        
        try {
            
            //找到有多少个钻场
            ArrayList<ZuanChang_Model> zcms=OperateMyDatabaseImpl.getAllResult(AllGlobal.ZUANCHANG_SQL);
            int zcSize=zcms.size();
            for(int k=0;k<zcSize*2;k++){
                tList.add(k, 0);
            }
            Iterator<Node> it=clipGroup.getChildren().iterator();
            while (it.hasNext()) {
                boolean flagYX=false;
                Node aNode=it.next();
                Ellipse e=null;
                if(aNode.getId()!=null&&aNode.getUserData()!=null){
                    e=(Ellipse)aNode;
                    Iterator<Node> it_inner=clipGroup.getChildren().iterator();
                    float distance=0;
                    String zcName=((String)e.getUserData()).substring(1);
                    innerloop:while (it_inner.hasNext()) {
                        Node innerNode=it_inner.next();
                        if(innerNode.getId()!=null&&innerNode.getUserData()!=null){
                            Ellipse ei=(Ellipse)innerNode;
                            double x=e.getTranslateX()-ei.getTranslateX();
                            double y=e.getTranslateY()-ei.getTranslateY();
                            distance=FastMath.sqrt((float) (x*x+y*y));
                            if(distance!=0&&distance<=(wxkjlF*0.75f)){
                                //这是要处理三条分类的
                                for(int i=0;i<zcSize;i++){
                                    if(zcName.equals(zcms.get(i).getMingcheng())){
                                        tList.set(i, tList.get(i)+1);
                                    }
                                }
                                flagYX=true;
                                break innerloop;
                            }
                        }
                    }
                    if(!flagYX){
                        for(int i=zcSize;i<zcSize*2;i++){
                            if(zcName.equals(zcms.get(i-zcSize).getMingcheng())){
                                tList.set(i, tList.get(i)+1);
                            }
                        }
                    }
                }
            }
            return tList;
        } catch (Exception ex) {
            Logger.getLogger(DrillPage.class.getName()).log(Level.SEVERE, null, ex);
        }
        return tList;
    }
}

